<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>添加编辑收货地址</title>
  <meta name="renderer" content="webkit"/>
  <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
  <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <script src="http://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js"></script>
</head>
<body>
    <div>
        姓名：<input type="text" name="consignee" value="{$address.consignee}"><br/>
        电话：<input type="text" name="mobile" value="{$address.mobile}"><br/>
        省份：<input type="text" name="province" value="{$address.province}"><br/>
        城市：<input type="text" name="city" value="{$address.city}"><br/>
        区：<input type="text" name="area" value="{$address.area}"><br/>
        详细地址：<input type="text" name="address" value="{$address.address}"><br/>
        是否默认：<input type="checkbox" name="is_default" value="1" {if condition="$address.is_default eq 1"} checked {/if}><br/>
        <input type="button" value="提交" onclick="handup()">
        <input type="hidden" name="id" value="{$id}">
    </div>
</body>
</html>
<script>
  /**
   *  提交保存
   */
  function handup(){
      var reg = /^1[34578]\d{9}$/;
      var id = $('input[name=id]').val();
      var mobile = $('input[name=mobile]').val();
      var consignee = $('input[name=consignee]').val();
      var province = $('input[name=province]').val();
      var city = $('input[name=city]').val();
      var area = $('input[name=area]').val();
      var address = $('input[name=address]').val();
      var is_default = $('input[name=is_default]').val();
      if(mobile == ''){
          alert('请输入手机号');
          return false;
      }
      if(!reg.test(mobile)){
          alert('手机格式错误！');
          return false;
      }
      if(consignee == ''){
          alert('请输入收货人');
          return false;
      }
      if(province == ''){
          alert('请输入省份');
          return false;
      }
      if(city == ''){
          alert('请输入城市');
          return false;
      }
      if(area == ''){
          alert('请输入地区');
          return false;
      }
      if(address == ''){
          alert('请输入详细地址');
          return false;
      }
      $.post("{:url('User/add_edit_address')}",
          {id:id,mobile:mobile,consignee:consignee,province:province,city:city,area:area,address:address,is_default:is_default},
          function(data){
          console.log(data);
              if(data.code == 1){
                  alert('保存成功');
                  window.location.href = "{:url('User/index')}";
              }else{
                  alert(data.msg);
              }
          }
      );
  }
</script>